//
//  ThCharacterBrowserPanelController.m
//  Thanatos
//
//  Created by Joel Owens on 5/12/10.
//  Copyright 2010 Na'Shenassi.org. All rights reserved.
//

#import "ThCharacterBrowserPanelController.h"


@implementation ThCharacterBrowserPanelController


  - (ThCharacterBrowserPanelController *)init {
    if (self = [super initWithWindowNibName:@"CharacterBrowser"]) {
      userDefaults = [NSUserDefaults standardUserDefaults];
    }
    return self;
  }

  - (void)awakeFromNib {
    [self imageBrowserInitializeSettings];
  }






/// Image Browser Methods

  - (void)imageBrowserChangeZoomValueWithEvent:(NSEvent *)event {
    float amount = [event magnification];
    float originalAmount = [sliderForCharacterBrowserZoomControl floatValue];
    float newAmount = amount + originalAmount;
    if( newAmount < 0.0000000) {
      newAmount = 0.000000000;
    }
    if( newAmount > 1.0 ) {
      newAmount = 1.0;
    }
    [sliderForCharacterBrowserZoomControl setFloatValue:newAmount];
    [self imageBrowserChangeZoomValue:sliderForCharacterBrowserZoomControl];
    [sliderForCharacterBrowserZoomControl performClick:self];
  }

  - (IBAction)imageBrowserChangeZoomValue:(id)sender {
    [imageBrowserForCharacterBrowser setZoomValue:[sender floatValue]];
  }

  - (void)imageBrowserInitializeSettings {
    [imageBrowserForCharacterBrowser setAllowsMultipleSelection:NO];
    [imageBrowserForCharacterBrowser setAllowsEmptySelection:NO];
    [imageBrowserForCharacterBrowser setAnimates: YES];
    [imageBrowserForCharacterBrowser setCellsStyleMask:(IKCellsStyleShadowed | IKCellsStyleTitled | IKCellsStyleSubtitled)];
    [imageBrowserForCharacterBrowser setValue:[NSColor colorWithCalibratedRed:0.41 green:0.18 blue:0.21 alpha:1.0] forKey:IKImageBrowserBackgroundColorKey];
    //[imageBrowserForCharacterBrowser setValue:[NSColor colorWithRed:93 green:14 blue:18 alpha:65] forKey:IKImageBrowserBackgroundColorKey];
    [imageBrowserForCharacterBrowser setConstrainsToOriginalSize:NO];
    
    
    [[imageBrowserForCharacterBrowser valueForKey:IKImageBrowserCellsTitleAttributesKey] setValue:[NSFont fontWithName:@"Helvetica" size:10] forKey:@"NSFontAttributeName"];
    
    [imageBrowserForCharacterBrowser bind:@"content"
                                 toObject:[[NSApp delegate] arrayControllerForCharacterBrowser]
                              withKeyPath:@"arrangedObjects"
                                  options:NULL];
    [imageBrowserForCharacterBrowser bind:@"selectionIndexes"
                              toObject:[[NSApp delegate] arrayControllerForCharacterBrowser]
                           withKeyPath:@"selectionIndexes"
                               options:NULL];
    [self imageBrowserChangeZoomValue:sliderForCharacterBrowserZoomControl];
    
  }

  - (void)imageBrowser:(IKImageBrowserView *)aBrowser cellWasDoubleClickedAtIndex:(NSUInteger)index {
  [imageBrowserForCharacterBrowser setSelectionIndexes:[NSIndexSet indexSetWithIndex:index] byExtendingSelection:NO];
  [[NSApp delegate] openCharacter:self];
}

//// Event Responders


@end
